<?php
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation class
include_once("Users.php");							//--> User
include_once("Logs.php");							//--> logs class
require_once("controlHeader.php");					//--> system control header

$objOperate	= new Operation($sessionImpl->getLanguage());	//--> Operation instance
$objLogs 	= new Logs($uid);								//--> logs instance
$objUser 	= new Users($uid);								//--> user

$selfFileName = '';
$error_message 		= '';
$strMenuGroupName 	= '';

if(isset($_GET['keyword']) && !empty($_GET['keyword'])){
	$keyword 	= $_GET['keyword'];
	$where 		= " WHERE userid=$keyword ORDER BY id DESC";
}else{
	$where 		= ' ORDER BY id DESC';
	$keyword 	= '';
}

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);
if(count($arrOperate) > 0){
	$strQuery = $_SERVER["REQUEST_URI"];
	$arrUrlInfo 	= pathinfo($strQuery);
	$selfFileName	= $arrUrlInfo['filename'];
	
	$arrOperateAllInfo = $objOperate->listFromCustom($arrOperate, " WHERE id in (".implode(",", $arrOperate).")");
	
	
	$i = 0; 
	foreach($arrOperateAllInfo as $key => $value){
		$strFileName = $selfFileName."_".$value['name'].".php";

		if(file_exists($strFileName)){
			$arrOperateInfo[$i]['name'] 		= $value['name'];
			$arrOperateInfo[$i]['viewName'] 	= $value['viewName'];
			
			$i++;
		}
	}
}

$arrDataList = $objLogs->listLoginLog($arrOperate, $where, $page, DISPLAY_DATA_SIZE, '');
foreach($arrDataList as $key => $value){
	$arrUserInfo = $objUser->getFromID($arrOperate, $value['userid']);
	$arrDataList[$key]['username'] = $arrUserInfo['name'];
}

/*----- out html -----*/
$smarty = new Smarty();					//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_DIR;

$smarty->assign('error_message', $error_message);
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('selfFileName', $selfFileName);
$smarty->assign('arrOperateInfo', $arrOperateInfo);

$smarty->assign('arrDataList', $arrDataList);
$smarty->assign('keyword', $keyword);
$smarty->assign('PAGE_BAR', $objLogs->pagenav);

$smarty->display('listLoginLog.htm');
?>
